anime.easings.noEase = function() {
    return 1
}
,
anime.easings.bulbEasing = function(e) {
    return e > .5 ? 1 : 0
}
;
var SimianCI = {
    init: function() {
        this.nav(),
        this.mobileMenu(),
        this.animatePage()
    },
    animatePage: function() {
        switch (window.location.pathname) {
        case "/":
            this.leadAnimation()
        }
    },
    nav: function() {
        function e(e) {
            t.hasClass("navbar--show") && e || (n.toggleClass("navbar--show", !e),
            t.toggleClass("navbar--show", e))
        }
        function i() {
            e($(window).scrollTop() > r)
        }
        var n = $("#navbar")
          , t = $("#navbar-inverse")
          , r = 20
          , a = $("#mobile-menu");
        i(),
        $(document).scroll(function(e) {
            if (a.hasClass("mobile-menu--active"))
                return void e.preventDefault();
            i()
        })
    },
    mobileMenu: function() {
        function e() {
            n.toggleClass("menu-toggle--active"),
            r.toggleClass("mobile-menu--active"),
            t.toggleClass("modal-open")
        }
        var i = $(".menu-toggle-wrapper")
          , n = $(".menu-toggle")
          , t = $(document.body)
          , r = $("#mobile-menu");
        i.on("click", function(i) {
            e()
        })
    },
    leadAnimation: function() {
        function e() {
            for (var n, t = 0; t < u.length; t++) {
                n = i(n, u[t])
            }
            n.then(function() {
                setTimeout(function() {
                    requestAnimationFrame(e)
                }, m.timeToRestart)
            })
        }
        function i(e, i) {
            var n = i.wire;
            return e = void 0 === e ? h(n) : e.then(i.turnWireOn),
            e = e.then(function() {
                return Promise.all([d().then(g).then(f), i.animateLights()])
            }).then(i.turnWireOff).then(i.fixLights)
        }
        function n(e) {
            var i = document.querySelectorAll("#lead-svg .cable_" + e);
            return [].slice.call(i)
        }
        function t(e) {
            var i = document.querySelectorAll("#lead-svg #server_" + e + ' *[fill="#93E10E"]');
            return [].slice.call(i)
        }
        function r(e, i) {
            return i * m.timeBetweenServerLights
        }
        function a(e, i) {
            return anime({
                targets: i,
                easing: "easeInOutSine",
                duration: e.duration,
                delay: function(e, i) {
                    return 50 * i
                },
                fillOpacity: e.fillOpacity,
                strokeWidth: e.strokeWidth,
                stroke: e.stroke
            }).finished
        }
        function l(e, i) {
            return anime({
                targets: i,
                duration: e.duration,
                delay: e.delay,
                easing: "bulbEasing",
                fill: e.fill
            }).finished
        }
        function o(e, i) {
            var n = anime({
                targets: "#lead-svg #lamp .bulb-light",
                delay: 0,
                loop: e.loop,
                easing: "bulbEasing",
                duration: e.duration,
                fillOpacity: e.opacity,
                fill: i.stroke
            }).finished;
            if (i) {
                var t = anime({
                    targets: "#lead-svg #lamp .bulb-glass",
                    delay: 0,
                    loop: e.loop,
                    easing: "bulbEasing",
                    duration: e.duration,
                    stroke: i.stroke
                }).finished;
                return Promise.all([n, t])
            }
            return n
        }
        var s = $(".lead-svg")
          , u = (document.querySelectorAll("#lead-svg #monkey .face-item"),
        [{
            wireNumber: "01",
            serverNumber: "01"
        }, {
            wireNumber: "02",
            serverNumber: "02"
        }, {
            wireNumber: "03",
            serverNumber: "03"
        }]);
        s.addClass("lead-svg--show");
        var m = {
            timesServerLights: 600,
            timeBetweenServerLights: 300,
            timeToRestart: 1600,
            bulbDuration: 840,
            bulbLoops: 6,
            initialDrawingTime: 120,
            wiresTime: 1e3
        }
          , c = {
            inchWorm: "#93E10E",
            monza: "#D0011B",
            carnation: "#F15569",
            webOrange: "#FFA300",
            silver: "#C2C2C2",
            altSilver: "#BCBCBC"
        }
          , d = o.bind(null, {
            duration: 100,
            loop: !1,
            opacity: 1
        }, {
            stroke: c.monza
        })
          , g = o.bind(null, {
            duration: m.bulbDuration,
            loop: m.bulbLoops,
            opacity: 1
        }, {
            stroke: [c.monza, c.carnation]
        })
          , f = o.bind(null, {
            duration: 100,
            loop: !1,
            opacity: 0
        }, {
            stroke: c.altSilver
        })
          , b = l.bind(null, {
            delay: r,
            duration: m.timesServerLights,
            fill: c.monza
        })
          , v = l.bind(null, {
            delay: r,
            duration: 100,
            duration: m.timesServerLights,
            fill: c.inchWorm
        })
          , h = a.bind(null, {
            duration: m.wiresTime,
            fillOpacity: 1,
            stroke: c.webOrange,
            strokeWidth: 2.25
        })
          , p = a.bind(null, {
            duration: m.wiresTime,
            fillOpacity: 0,
            stroke: c.silver,
            strokeWidth: 1
        });
        u.map(function(e) {
            var i = e;
            return i.wire = n(e.wireNumber),
            i.lights = t(e.serverNumber),
            i.turnWireOn = h.bind(null, i.wire),
            i.animateLights = b.bind(null, i.lights),
            i.turnWireOff = p.bind(null, i.wire),
            i.fixLights = v.bind(null, i.lights.concat().reverse()),
            i
        });
        new Vivus("lead-svg",{
            duration: m.initialDrawingTime,
            type: "delayed",
            animTimingFunction: Vivus.EASE,
            pathTimingFunction: Vivus.EASE_OUT
        },function() {
            requestAnimationFrame(e)
        }
        );
        setTimeout(function() {
            requestAnimationFrame(function() {
                anime({
                    targets: document.querySelectorAll(".non-regular"),
                    easing: "easeInOutSine",
                    duration: 300,
                    fillOpacity: 1
                })
            })
        }, 300)
    },
    Timer: function(e, i) {
        this.callback = e,
        this.time = i,
        this.createTimer = function() {
            this.interval = setInterval(this.callback, this.time)
        }
        ,
        this.resetTimer = function() {
            clearInterval(this.interval),
            this.createTimer()
        }
        ,
        this.createTimer()
    }
};
$(document).ready(function() {
    SimianCI.init()
});
